/*
Copyright (C) 2011  Christoph Schnack, Berlin (Germany)

This file is part of Tribuit.

    Tribuit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Tribuit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Tribuit.  If not, see <http://www.gnu.org/licenses/>.
*/
package GuiTools;

import java.util.*;

import javax.swing.*;
import Settings.*;
import Storage.TermClass;

/**
 * @author Christoph Schnack
 *
 */
public class MetaPanel extends JPanel{
	HashMap<String,MetaElement> metaElementsHM;
	TermClass termClass;
	Settings SET;
	
	public MetaPanel(Settings setArg, TermClass termClassArg){
		super();
		termClass = termClassArg;
		SET = setArg;
		metaElementsHM = new HashMap<String,MetaElement>();
		setPanel();
	}
	
	public void setPanel(){
		for(String name : termClass.getSortedKeys()){
			metaElementsHM.put(name,new MetaElement(SET,name,termClass.getValues(name)));
			this.add(metaElementsHM.get(name));
		}
	}
	
	public String getMetaValue(String name){
		return (!metaElementsHM.isEmpty())?metaElementsHM.get(name).getValue():null;
	}
	
	public void reset(){
		this.removeAll();
		metaElementsHM.clear();
	}
	
	public void setTermClass(TermClass tc){
		termClass = tc;
		reset();
		setPanel();
	}
	
	public void resetAllFields(){
		if(!metaElementsHM.isEmpty()){
			for(String s : metaElementsHM.keySet()){
				metaElementsHM.get(s).reset();
			}
		}
	}
}
